package info.motteke.mixivoice4j.http.json.comment.get;

import info.motteke.mixivoice4j.Body;
import info.motteke.mixivoice4j.ImageUrl;
import info.motteke.mixivoice4j.http.StringImageUrl;
import net.arnx.jsonic.JSONHint;

import org.jsoup.Jsoup;

public class JsonComment {

    private String thumbnail;

    private String nickname;

    private long commentMemberId;

    private boolean canDelete;

    private long commentPostTime;

    private String bodyHtml;

    public ImageUrl getThumbnail() {
        return new StringImageUrl(thumbnail);
    }

    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = unescape(nickname);
    }

    private String unescape(String string) {
        return string.replaceAll("&gt;", ">").replaceAll("&lt;", "<");
    }

    @JSONHint(name = "comment_member_id")
    public long getCommentMemberId() {
        return commentMemberId;
    }

    @JSONHint(name = "comment_member_id")
    public void setCommentMemberId(long commentMemberId) {
        this.commentMemberId = commentMemberId;
    }

    @JSONHint(name = "can_delete")
    public boolean canDelete() {
        return canDelete;
    }

    @JSONHint(name = "can_delete")
    public void setCanDelete(boolean canDelete) {
        this.canDelete = canDelete;
    }

    @JSONHint(name = "comment_post_time")
    public long getCommentPostTime() {
        return commentPostTime;
    }

    @JSONHint(name = "comment_post_time")
    public void setCommentPostTime(long commentPostTime) {
        this.commentPostTime = commentPostTime;
    }

    @JSONHint(name = "body_html")
    public String getBodyHtml() {
        return getBody().toString();
    }

    public Body getBody() {
        return new Body(Jsoup.parse(bodyHtml).select("body").get(0));
    }

    @JSONHint(name = "body_html")
    public void setBodyHtml(String bodyHtml) {
        this.bodyHtml = bodyHtml;
    }
}